package com.zhejiangzhengyuan.municipal_common.mapper;

import com.zhejiangzhengyuan.municipal_common.entity.File;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;


/**
 * <p>
 * 文件表，目前将文件数据单独列为一个数据库进行处理，目的是为了可能出现的情况（单独的文件中心，文件存储拓展） Mapper 接口
 * </p>
 *
 * @author linju
 * @since 2019-11-22
 */
@Repository
public interface FileMapper extends BaseMapper<File> {
    @Select(" SELECT f.* FROM warn_event w,file f,warn_event_file_mapping wf WHERE wf.warn_event_id=w.id and wf.file_id=f.\"id\" and w.id=#{wid} LIMIT 1")
    File selectByWid(@Param("wid") Long wid);

    @Select("  SELECT f.* FROM \"case\" ca,receipt r,case_receipt_mapping crp,file f,receipt_file_mapping rfp\n" +
            "            WHERE crp.case_id=ca.\"id\" and crp.receipt_id=r.\"id\" and rfp.receipt_id=r.\"id\" and rfp.file_id=f.\"id\" and ca.\"id\"=#{cid} LIMIT 1")
    File selectByCid(@Param("cid") Long cid);


    @Select(" SELECT f.* FROM inspection_event w,file f,inspection_event_file_mapping wf WHERE wf.inspection_event_id=w.id and wf.file_id=f.\"id\" and w.id=#{iid} LIMIT 1")
    File selectInspectionFile(@Param("iid") Long iid);

    List<String> selectByMid(@Param("mid") Long mid);


    List<String> selectByBid(@Param("bid")  Long bid);

    List<String> selectByRid(@Param("rid") Long rid);

    List<String> selectByIid(@Param("iid") Long iid);


    List<String> selectBySid(@Param("sid") Long sid);
}
